<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="keywords" content="">
<meta name="description" content="">
<title>参赛报名信息</title>
  <link href=" {{asset('css/style.css')}}" rel="stylesheet" type="text/css">

</head>
<body>
<div class="wrap">

  <div class="top">
    <a class="btn_back" href="javascript:history.back(-1);"></a>
    <div class="tit">参赛报名信息</div>
    
  </div>

<div class="main">
  <div class="list_tgy">
    <ul>
      @if( count($lists)>0 )
        @foreach($lists as $key => $list)
          <li>
            <p>{{$list->advertisement}}</p>
            <div class="about">
              <div class="t_name"><span>{{$list->nickname}}</span></div>
              <div class="num"><span>{{$list->vote}}</span></div>
              <div class="btn_tp" name="voteit" tip="{{$list->id}}">投票</div>
              <div class="clear"></div>
            </div>
          </li>
        @endforeach
      @else
        <li>
          <p>没有数据</p>
        </li>
      @endif

    </ul>
    <ul>
      <li id="loadMore" style="width: 35%;margin: 20px auto;border: none;">
        <div style="height: 50px;line-height: 50px;border:1px solid #F08B53;border-radius: 8px;color:#F08B53;font-size: large;font-weight: 500; ">加载更多</div>
      </li>
    </ul>
  </div>
</div>
</div>
<script type="text/javascript" src="{{asset('js/jquery-1.9.1.js')}}"></script>
<script src="{{url('/js/common.js')}}" type="text/javascript" language="javascript"></script>
<script type="text/javascript">
  $(function(){
    //点击投票
    $(".list_tgy").on("click","div[name='voteit']", function(){
      var that = $(this).prev().find('span');
      var postData = {
        ip:$.getIPAddress(),
        id:$(this).attr('tip'),
        _token:"{{ csrf_token() }}"
      };
      $.ajax({
        type: "POST",
        url: "{{url('contest/vote')}}",
        data: postData,
        async: false
      }).success(function(data){
        if(data.state == 'success'){
          alert("提交成功");
          var vote = parseInt( $(that).html() ) + 1;
          $(that).html(vote);
        }else{
          alert(data.message);
        }
      })
    });

    //点击加载更多
    var currentPage = 1;
    $("#loadMore").on("click", function(){
      currentPage++;
      $.ajax({
        url:"{{url('contest/list')}}" + "?page=" + currentPage,
        type:"GET",
        async:true,
      }).done(function(data){
        currentPage = data.current_page;
        var html = [];
        if(data.data.length>0) {
          var data = data.data;
          var i = 0;
          while(data[i]){
            html.push('<li>');
            html.push('<p>'+data[i].advertisement+'</p>');
            html.push('<div class="about">');
            html.push('<div class="t_name"><span>'+data[i].advertisement+'</span></div>');
            html.push('<div class="num"><span>'+data[i].vote+'</span></div>');
            html.push('<div class="btn_tp" name="voteit" tip="'+ data[i].id +'">投票</div>');
            html.push('<div class="clear"></div>');
            html.push('</div>');
            html.push('</li>');
            i++;
          }
          $(".list_tgy ul:first").append(html.join(''));
        }else{
          $("#loadMore div").html('没有更多数据');
        }
      });
    });
  })
</script>
</body>
</html>